package com.example.mpandroidchartdemo;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;

import java.util.ArrayList;
import java.util.List;

public class HorizontalBarChartActivity extends AppCompatActivity {

    private BarChart mBarChart;
    List<BarEntry> list = new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.horizontal_bar_chart_activity);
        mBarChart = findViewById(R.id.horizontal_bar_chart);

        // 添加数据
        list.add(new BarEntry(1,3));
        list.add(new BarEntry(2,5));
        list.add(new BarEntry(3,6));
        list.add(new BarEntry(4,4));
        list.add(new BarEntry(5,2));

        BarDataSet barDataSet = new BarDataSet(list,"横向条形图");
        BarData barData = new BarData(barDataSet);
        mBarChart.setData(barData);

        mBarChart.getDescription().setEnabled(false); // 隐藏右下角英文

        // X轴 左侧
        mBarChart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM); // X轴的位置 默认为右边

        // Y轴 下方
        mBarChart.getAxisLeft().setEnabled(false); // 隐藏上侧Y轴 默认是上下两侧都有Y轴
    }
}
